package com.yoso.core.bo;


import lombok.Data;

/**
 * <p>
 * 统一返回体
 * </p>
 *
 * @author Michael Xu
 * @version 1.0
 * @date 2023/2/27 10:20
 */
@Data
public class ResponseResult<T> {

    private int status;

    private String message;

    private T data;

    public ResponseResult() {
        init(null);
    }

    public ResponseResult(T data) {
        init(data);
    }



    private ResponseResult(T data, int status, String message) {
        init(data, status, message);
    }

    private ResponseResult(int status, String message) {
        init(status, message);
    }


    public static <T> ResponseResult<T> success(T t) {
        return new ResponseResult<>(t);
    }


    public static <T> ResponseResult<T> success(T t, int status, String message) {
        return new ResponseResult<>(t, status, message);
    }

    public static ResponseResult<Object> success() {
        return new ResponseResult<>();
    }

    public static <T> ResponseResult<T> error(int status, String message) {
        return new ResponseResult<>(status, message);
    }

    public static <T> ResponseResult<T> error(String message) {
        return new ResponseResult<>(500, message);
    }

    private void init(T data) {
        this.status = 200;
        this.message = "success";
        this.data = data;
    }

    private void init(T data, int status, String message) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    private void init(int status, String message) {
        this.status = status;
        this.message = message;
    }

}
